package com.weixin.paleituo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.base.BaseRecycleAdapter;
import com.weixin.paleituo.bean.ChildrenBeanXX;
import com.weixin.paleituo.help.RecycleViewHolder;

import java.util.List;

/**
 * Author yichao
 * Time  2017/12/1 0:38
 * Dest 商品分类
 */

public class ClassifyMenuRecyclerViewAdapter extends BaseRecycleAdapter<ChildrenBeanXX> {

    private int checkPosition;
    private TextView mTvNemu;
    private LinearLayout mLlitemRoot;

    public ClassifyMenuRecyclerViewAdapter(Context context, List<ChildrenBeanXX> list) {
        super(context,list,R.layout.classify_menu_item_layout);
    }
    public void setCheckPostion(int postion){
        checkPosition=postion;
    }
    private OnItemClickListener mOnItemClickListener;

    @Override
    protected void setData(RecycleViewHolder holder,final ChildrenBeanXX childrenBeanXX, final int position) {

        mTvNemu = holder.getItemView(R.id.tv_item_menu_sale_status_menu_item_layout);
        mLlitemRoot = holder.getItemView(R.id.ll_itemroot_sale_status_menu_item);
         View viewline  =holder.getItemView(R.id.viewline_item_menu_sale_status_menu_item_layout);
        if (checkPosition==position){
            mTvNemu.setSelected(true);
            mLlitemRoot.setSelected(true);

        }else {
            mTvNemu.setSelected(false);
            mLlitemRoot.setSelected(false);
        }

        mTvNemu.setText(childrenBeanXX.getName()+"");

        if (mOnItemClickListener != null) {
            mLlitemRoot.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onClick(v, position,childrenBeanXX.getId()+"");
                }
            });

        }
if (position==getItemCount()-1){
    viewline.setVisibility(View.INVISIBLE);
}




    }

    public interface OnItemClickListener {
        public void onClick(View v, int position, String categoryId);

    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;

    }


}
